using System;
using IrisGenerator.Framework.Database;
namespace IrisGenerator.Common.DatabaseModel {
    
    
    public partial class Table {
        public static Table LoadByNameAndOwner(Table tableToFind)
        {
            if (tableToFind == null ||
                string.IsNullOrEmpty(tableToFind.TabName) ||
                string.IsNullOrEmpty(tableToFind.TabOwner)
                )
                return null;
            try
            {
                DataAccess.Table dbo = new IrisGenerator.Common.DatabaseModel.DataAccess.Table();
                object result=dbo.SelectTableFromNameAndOwner(tableToFind.TabName, tableToFind.TabOwner);
                Guid? tableId = SqlConvert.ToGuid(result);
                if (tableId == null)
                    return null;
                return Table.Load(tableId);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private ConstraintCollection _constraints=null;

        public ConstraintCollection Constraints
        {
            get
            {
                if (_constraints == null)
                    _constraints = ConstraintCollection.GetTableConstraints(this);
                return _constraints;
            }
        }

        
    }
}
